package com.security.core.social.qq.config;

import com.security.core.social.SecurityConnectedView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

import com.security.core.properties.QQProperties;
import com.security.core.properties.SecurityProperties;
import com.security.core.social.qq.connect.QQConnectFactory;
import org.springframework.web.servlet.View;

/**
 * @title QQAutoConfig
 * @version 1.0.0
 * @description 
 * @author Dark_blue
 * @date 2019年11月12日
 */
@Configuration
@ConditionalOnProperty(prefix = "security.social.qq", name = "app-id")
public class QQAutoConfig extends SocialAutoConfigurerAdapter{
	

	private SecurityProperties securityProperties;

	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		// TODO Auto-generated method stub
		
		QQProperties qqProperties = securityProperties.getSocial().getQq();
		return new QQConnectFactory(qqProperties.getProviderId(), qqProperties.getAppId(), qqProperties.getAppSecret());
	}

	@Bean("connect/qqConnected")
	@ConditionalOnMissingBean(name = "qqConnectedView")
	public View qqConnectedView(){
		return new SecurityConnectedView();
	}

	public SecurityProperties getSecurityProperties() {
		return securityProperties;
	}

	@Autowired
	public void setSecurityProperties(SecurityProperties securityProperties) {
		this.securityProperties = securityProperties;
	}
}
